package com.jsh.erp.controller;

import com.jsh.erp.domain.param.PrintParam;
import com.jsh.erp.domain.vo.ReturnPrintVo;
import com.jsh.erp.domain.vo.SaleOutPrintVo;
import com.jsh.erp.service.print.PrintService;
import com.jsh.erp.utils.BaseResponseInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/print")
@Api(tags = {"打印相关"})
public class PrintController {

    private Logger logger = LoggerFactory.getLogger(PrintController.class);

    @Resource
    private PrintService printService;

    @PostMapping(value = "/saleOutPrintData")
    @ApiOperation(value = "仓库出库打印发票")
    public BaseResponseInfo saleOutPrintData(@RequestBody PrintParam param) throws Exception {
        if (param.getId() == null) {
            return BaseResponseInfo.fail(500, "param error");
        }
        BaseResponseInfo res = new BaseResponseInfo();
        try {
            SaleOutPrintVo saleOutPrintVo = printService.getSaleOutPrintData(param.getId());
            res.code = 200;
            res.data = saleOutPrintVo;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            res.code = 500;
            res.data = "system data error";
        }
        return res;
    }

    @PostMapping(value = "/returnPrintData")
    @ApiOperation(value = "退货打印单据")
    public BaseResponseInfo returnPrintData(@RequestBody PrintParam param) {
        if (param.getId() == null) {
            return BaseResponseInfo.fail(500, "param error");
        }
        BaseResponseInfo res = new BaseResponseInfo();
        try {
            ReturnPrintVo returnPrintVo = printService.getReturnPrintData(param.getId());
            res.code = 200;
            res.data = returnPrintVo;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            res.code = 500;
            res.data = "system data error";
        }
        return res;
    }


}
